home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!tektronix!tekgen!tekred!games
- From: games@tekred.CNA.TEK.COM
- Newsgroups: comp.sources.games
- Subject: v06i015: tetrix - ancient Russian(?) fill the holes game
- Message-ID: <3662@tekred.CNA.TEK.COM>
- Date: 28 Feb 89 20:00:21 GMT
- Sender: billr@tekred.CNA.TEK.COM
- Lines: 2055
- Approved: billr@saab.CNA.TEK.COM
-
- Submitted-by: ncrlnk!ncrcae!quentin@uunet.uu.net
- Posting-number: Volume 6, Issue 15
- Archive-name: tetrix
-
- [I haven't been able to try this, not having a System V OS,
- but it sounds like fun. -br]
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: README Rotate.c Makefile tet.h AdvanceP.c MoveL.c MoveR.c
- # NewP.c Rotate.c tet.c
- # Wrapped by billr@saab on Tue Feb 28 11:22:44 1989
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(1828 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- X This is a Unix SysV implementation of a game that appeared on
- Xcomp.binaries.amiga a while ago. The author, Quentin Neill,
- Xsaw it on an amiga here at work, and ported it to curses
- X(on his own time, of course ;-) ).
- X I'm not too sure about the history of tetrix. Someone
- Xsaid that the game originated in Russia, and that it is quite old.
- XWe became enthralled with the game on an Amiga, almost to the point
- Xof addiction. That version had some documentation, but I never had
- Xthe chance to read it - I only played. I considered writing a version
- Xin machine language for my Franklin junker at home, but settled on a
- XC implementation for unix machines.
- X The object of the game is to keep the board clear for as long as
- Xpossible. Pieces consisting of four blocks (hence the name TETRix) in the
- Xseven possible arrangements are sent down one at a time. The player's
- Xjob is to find the best fit for the piece in the pile of blocks that have
- Xalready fallen. He can rotate each piece and move it from side to side.
- XIf the piece just played causes a complete row of blocks, that row is
- Xerased and all blocks above it move down one row. Points are awarded for
- Xcompleted rows - more for rows higher up on the board. A piece may
- Xbe dropped from a height for additional points when the player feels it
- Xis oriented correctly. The game is over when no more pieces can be formed
- Xat the top of the board.
- X There is one variable INIT_PAUSE in tet.c that compensates for
- Xdifferent machine speeds. Set this higher if tetrix screams, and the
- Xtime between each piece's movement will lengthen. Set it lower if
- Xit crawls along too slowly. On a Tower 32/800 with about 45 users on a
- Xbusy day, we do well with the value set at about 300. On a Tower 32/200
- Xwith one user, the value was set at 1500.
- X
- X Good luck! Quentin Neill
- X
- END_OF_FILE
- if test 1828 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'Rotate.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Rotate.c'\"
- else
- echo shar: Extracting \"'Rotate.c'\" \(6209 characters\)
- sed "s/^X//" >'Rotate.c' <<'END_OF_FILE'
- X
- X#include <curses.h>
- X#include "tet.h"
- X/*********************************************************************/
- X/* Switch on type of piece, find out if I can rotate */
- X/* If so, then do it */
- X/*********************************************************************/
- XRotate()
- X{
- Xswitch (Type) {
- X /* WHITE PIECES */
- X case W_TYPE : /* checked */
- X if (IS_FREE(Column,Row-1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,W_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row)) {
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,W_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-2 : /* checked */
- X if (IS_FREE(Column,Row+1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,W_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-3 : /* checked */
- X if (IS_FREE(Column+1,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,W_CHAR);
- X Type = W_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* RED PIECES */
- X case R_TYPE : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,R_CHAR);
- X PUTCH(Column,Row+1,R_CHAR);
- X PUTCH(Column+1,Row+1,R_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row-1) &&
- X IS_FREE(Column+1,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,R_CHAR);
- X PUTCH(Column+1,Row-1,R_CHAR);
- X PUTCH(Column+1,Row,R_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-2 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column,Row-1) &&
- X IS_FREE(Column,Row+1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row-1,R_CHAR);
- X PUTCH(Column,Row-1,R_CHAR);
- X PUTCH(Column,Row+1,R_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column+1,Row)) {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,R_CHAR);
- X PUTCH(Column-1,Row+1,R_CHAR);
- X PUTCH(Column+1,Row,R_CHAR);
- X Type = R_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* TAN PIECES */
- X case T_TYPE :
- X case T_TYPE-1 :
- X case T_TYPE-2 :
- X case T_TYPE-3 : goto out;
- X
- X /* YELLOW PIECES */
- X case Y_TYPE :
- X case Y_TYPE-2 : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,Y_CHAR);
- X PUTCH(Column+1,Row+1,Y_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case Y_TYPE-1 :
- X case Y_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row+1,Y_CHAR);
- X PUTCH(Column,Row+1,Y_CHAR);
- X Type = Y_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* GREEN PIECES */
- X case G_TYPE :
- X case G_TYPE-2 : /* checked */
- X if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1)) {
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row+1,G_CHAR);
- X PUTCH(Column,Row-1,G_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case G_TYPE-1 :
- X case G_TYPE-3 : /* checked */
- X if (IS_FREE(Column,Row+1) && IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,G_CHAR);
- X PUTCH(Column+1,Row+1,G_CHAR);
- X Type = G_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X
- X /* BLUE PIECES */
- X case B_TYPE : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row-1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,B_CHAR);
- X PUTCH(Column,Row+1,B_CHAR);
- X PUTCH(Column+1,Row-1,B_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column+1,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row-1,B_CHAR);
- X PUTCH(Column-1,Row,B_CHAR);
- X PUTCH(Column+1,Row,B_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-2 : /* checked */
- X if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1) &&
- X IS_FREE(Column,Row+1)) {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,B_CHAR);
- X PUTCH(Column,Row-1,B_CHAR);
- X PUTCH(Column,Row+1,B_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,B_CHAR);
- X PUTCH(Column+1,Row,B_CHAR);
- X PUTCH(Column+1,Row+1,B_CHAR);
- X Type = B_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* VIOLET PIECES */
- X case V_TYPE :
- X case V_TYPE-2 : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) &&
- X IS_FREE(Column,Row+2)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+2,Row,NO_CHAR);
- X PUTCH(Column,Row-1,V_CHAR);
- X PUTCH(Column,Row+1,V_CHAR);
- X PUTCH(Column,Row+2,V_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case V_TYPE-1 :
- X case V_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+2,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column,Row+2,NO_CHAR);
- X PUTCH(Column-1,Row,V_CHAR);
- X PUTCH(Column,Row,V_CHAR);
- X PUTCH(Column+1,Row,V_CHAR);
- X PUTCH(Column+2,Row,V_CHAR);
- X Type = V_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X default :
- X printf("illegal piece Type=%d!!\n",Type);
- X exit();
- X }
- Xbeepout:
- X if (Beep) beep();
- Xout:
- X refresh();
- X}
- X
- END_OF_FILE
- if test 6209 -ne `wc -c <'Rotate.c'`; then
- echo shar: \"'Rotate.c'\" unpacked with wrong size!
- fi
- # end of 'Rotate.c'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(633 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# - un'cpio' this in /usr/src or /usr/local/src or something - doesn't matter.
- X# - do a 'make install' in the tetrix directory
- X# - tetrix gets installed in /usr/lbin
- X# - this will create a high score file in /usr/tmp, so doing it again
- X# later on will erase high scores for the machine.
- X
- X
- XOBJS= MoveR.o MoveL.o NewP.o AdvanceP.o Rotate.o tet.o
- XINCS= tet.h
- X
- Xtetrix: $(OBJS) $(INCS)
- X cc -O $(OBJS) -o tetrix -lcurses
- X
- XMoveR.o: MoveR.c
- X
- XMoveL.o: MoveL.c
- X
- XNewP.o: NewP.c
- X
- XAdvanceP.o: AdvanceP.c
- X
- XRotate.o: Rotate.c
- X
- Xtet.o: tet.c
- X
- Xinstall: tetrix
- X chmod 755 tetrix
- X /bin/mv -f tetrix /usr/lbin
- X
- Xclean:
- X /bin/rm -rf tetrix core *.o
- END_OF_FILE
- if test 633 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'tet.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tet.h'\"
- else
- echo shar: Extracting \"'tet.h'\" \(1261 characters\)
- sed "s/^X//" >'tet.h' <<'END_OF_FILE'
- X#define NO_TYPE 0
- X#define NO_CHAR ' '
- X#define BRITE_CHAR '$'
- X
- X/* type numbers 1-3, 4-7, 9-11 etc represent the white, red, blue etc */
- X/* pieces at different rotations */
- X#define G_TYPE 4 /* Green pieces */
- X#define G_CHAR 'G'
- X#define R_TYPE 8 /* Red pieces */
- X#define R_CHAR 'R'
- X#define T_TYPE 12 /* Tan pieces */
- X#define T_CHAR 'O'
- X#define W_TYPE 16 /* White pieces */
- X#define W_CHAR 'W'
- X#define V_TYPE 20 /* Violet pieces */
- X#define V_CHAR 'V'
- X#define B_TYPE 24 /* Blue pieces */
- X#define B_CHAR 'B'
- X#define Y_TYPE 28 /* Yellow pieces */
- X#define Y_CHAR 'Y'
- X
- X#define MINX 15 /* defines corner screen position */
- X#define MINY 1
- X
- X#define BOARD_WIDE 10
- X#define BOARD_HIGH 20
- X
- X#define MAXX BOARD_WIDE+MINX
- X#define MAXY BOARD_HIGH+MINY
- X
- X#define STARTROW 1 /* defines starting position of pieces */
- X#define STARTCOL 5
- X
- Xextern int Type, Row, Column, Pause, CurrentSpeed, FallingDown, Beep;
- Xextern char Board[BOARD_WIDE][BOARD_HIGH];
- X
- X/* Macros */
- X/* offset the character on screen by MINX and MINY */
- X#define PUTCH(x,y,z) { mvaddch(y+MINY,x+MINX,z); Board[x][y]=z; }
- X
- X/* test whether a square is empty and legal */
- X/*
- X#define IS_FREE(x,y) (((y >= 0) && (y < BOARD_HIGH) && \
- X (x >= 0) && (x < BOARD_WIDE)) && \
- X (Board[x][y] == NO_CHAR))
- X*/
- XIS_FREE();
- END_OF_FILE
- if test 1261 -ne `wc -c <'tet.h'`; then
- echo shar: \"'tet.h'\" unpacked with wrong size!
- fi
- # end of 'tet.h'
- fi
- if test -f 'AdvanceP.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'AdvanceP.c'\"
- else
- echo shar: Extracting \"'AdvanceP.c'\" \(6864 characters\)
- sed "s/^X//" >'AdvanceP.c' <<'END_OF_FILE'
- X
- X#include <curses.h>
- X#include "tet.h"
- X/*********************************************************************/
- X/* Switch on type of piece, find out if I can move down */
- X/* If so, then do it and return 1 else return 0 */
- X/*********************************************************************/
- XAdvancePiece()
- X{
- Xswitch (Type) {
- X /* WHITE PIECES */
- X case W_TYPE :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+2) &&
- X IS_FREE(Column+1,Row+1))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,W_CHAR);
- X PUTCH(Column,Row+2,W_CHAR);
- X PUTCH(Column+1,Row+1,W_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case W_TYPE-1 :
- X if (IS_FREE(Column,Row+2) &&
- X IS_FREE(Column+1,Row+1))
- X {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+2,W_CHAR);
- X PUTCH(Column+1,Row+1,W_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case W_TYPE-2 :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+1))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,W_CHAR);
- X PUTCH(Column,Row+1,W_CHAR);
- X PUTCH(Column+1,Row+1,W_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case W_TYPE-3 :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+2))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row+1,W_CHAR);
- X PUTCH(Column,Row+2,W_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X
- X /* RED PIECES */
- X case R_TYPE :
- X if (IS_FREE(Column-1,Row+2) &&
- X IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+1))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+2,R_CHAR);
- X PUTCH(Column,Row+1,R_CHAR);
- X PUTCH(Column+1,Row+1,R_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case R_TYPE-1 :
- X if (IS_FREE(Column,Row+2) &&
- X IS_FREE(Column+1,Row+2))
- X {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column,Row+2,R_CHAR);
- X PUTCH(Column+1,Row+2,R_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case R_TYPE-2 :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+1))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row+1,R_CHAR);
- X PUTCH(Column,Row+1,R_CHAR);
- X PUTCH(Column+1,Row+1,R_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case R_TYPE-3 :
- X if (IS_FREE(Column-1,Row) &&
- X IS_FREE(Column,Row+2))
- X {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row,R_CHAR);
- X PUTCH(Column,Row+2,R_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X
- X /* TAN PIECES */
- X case T_TYPE :
- X case T_TYPE-1 :
- X case T_TYPE-2 :
- X case T_TYPE-3 :
- X if (IS_FREE(Column,Row+2) &&
- X IS_FREE(Column+1,Row+2))
- X {
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+2,T_CHAR);
- X PUTCH(Column+1,Row+2,T_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X
- X /* YELLOW PIECES */
- X case Y_TYPE :
- X case Y_TYPE-2 :
- X if (IS_FREE(Column-1,Row+2) &&
- X IS_FREE(Column,Row+2) &&
- X IS_FREE(Column+1,Row+1))
- X {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+2,Y_CHAR);
- X PUTCH(Column,Row+2,Y_CHAR);
- X PUTCH(Column+1,Row+1,Y_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case Y_TYPE-1 :
- X case Y_TYPE-3 :
- X if (IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+2))
- X {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,Y_CHAR);
- X PUTCH(Column+1,Row+2,Y_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X
- X /* GREEN PIECES */
- X case G_TYPE :
- X case G_TYPE-2 :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+2) &&
- X IS_FREE(Column+1,Row+2))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row+1,G_CHAR);
- X PUTCH(Column,Row+2,G_CHAR);
- X PUTCH(Column+1,Row+2,G_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case G_TYPE-1 :
- X case G_TYPE-3 :
- X if (IS_FREE(Column-1,Row+2) &&
- X IS_FREE(Column,Row+1))
- X {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,G_CHAR);
- X PUTCH(Column-1,Row+2,G_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X
- X /* BLUE PIECES */
- X case B_TYPE :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+2))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,B_CHAR);
- X PUTCH(Column,Row+1,B_CHAR);
- X PUTCH(Column+1,Row+2,B_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case B_TYPE-1 :
- X if (IS_FREE(Column,Row+2) &&
- X IS_FREE(Column+1,Row))
- X {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column,Row+2,B_CHAR);
- X PUTCH(Column+1,Row,B_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case B_TYPE-2 :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+1))
- X {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,B_CHAR);
- X PUTCH(Column,Row+1,B_CHAR);
- X PUTCH(Column+1,Row+1,B_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case B_TYPE-3 :
- X if (IS_FREE(Column-1,Row+2) &&
- X IS_FREE(Column,Row+2))
- X {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row+2,B_CHAR);
- X PUTCH(Column,Row+2,B_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X
- X /* VIOLET PIECES */
- X case V_TYPE :
- X case V_TYPE-2 :
- X if (IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+1) &&
- X IS_FREE(Column+2,Row+1))
- X {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+2,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,V_CHAR);
- X PUTCH(Column,Row+1,V_CHAR);
- X PUTCH(Column+1,Row+1,V_CHAR);
- X PUTCH(Column+2,Row+1,V_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X case V_TYPE-1 :
- X case V_TYPE-3 :
- X if (IS_FREE(Column,Row+3))
- X {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+3,V_CHAR);
- X Row +=1;
- X goto out;
- X }
- X else goto badout;
- X
- X default :
- X printf("Advance Piece: illegal piece Type=%d!!\n",Type);
- X exit();
- X }
- Xbadout:
- X return(0);
- Xout:
- X refresh();
- X return(1);
- X}
- END_OF_FILE
- if test 6864 -ne `wc -c <'AdvanceP.c'`; then
- echo shar: \"'AdvanceP.c'\" unpacked with wrong size!
- fi
- # end of 'AdvanceP.c'
- fi
- if test -f 'MoveL.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MoveL.c'\"
- else
- echo shar: Extracting \"'MoveL.c'\" \(6741 characters\)
- sed "s/^X//" >'MoveL.c' <<'END_OF_FILE'
- X
- X#include <curses.h>
- X#include "tet.h"
- X/*********************************************************************/
- X/* Switch on type of piece, find out if I can move left */
- X/* If so, then do it */
- X/*********************************************************************/
- XMoveLeft()
- X{
- Xswitch (Type) {
- X /* WHITE PIECES */
- X case W_TYPE : /* checked */
- X if (IS_FREE(Column-2,Row) && IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-2,Row,W_CHAR);
- X PUTCH(Column-1,Row+1,W_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row-1,W_CHAR);
- X PUTCH(Column-1,Row,W_CHAR);
- X PUTCH(Column-1,Row+1,W_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-2 : /* checked */
- X if (IS_FREE(Column-2,Row) && IS_FREE(Column-1,Row-1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column-2,Row,W_CHAR);
- X PUTCH(Column-1,Row-1,W_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-2,Row) &&
- X IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row-1,W_CHAR);
- X PUTCH(Column-2,Row,W_CHAR);
- X PUTCH(Column-1,Row+1,W_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* RED PIECES */
- X case R_TYPE : /* checked */
- X if (IS_FREE(Column-2,Row) && IS_FREE(Column-2,Row+1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column-2,Row,R_CHAR);
- X PUTCH(Column-2,Row+1,R_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row-1,R_CHAR);
- X PUTCH(Column-1,Row,R_CHAR);
- X PUTCH(Column-1,Row+1,R_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-2 : /* checked */
- X if (IS_FREE(Column-2,Row) && IS_FREE(Column,Row-1)) {
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-2,Row,R_CHAR);
- X PUTCH(Column,Row-1,R_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-3 : /* checked */
- X if (IS_FREE(Column-2,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-2,Row-1,R_CHAR);
- X PUTCH(Column-1,Row,R_CHAR);
- X PUTCH(Column-1,Row+1,R_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* TAN PIECES */
- X case T_TYPE :
- X case T_TYPE-1 :
- X case T_TYPE-2 :
- X case T_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,T_CHAR);
- X PUTCH(Column-1,Row+1,T_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* YELLOW PIECES */
- X case Y_TYPE :
- X case Y_TYPE-2 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column-2,Row+1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,Y_CHAR);
- X PUTCH(Column-2,Row+1,Y_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case Y_TYPE-1 :
- X case Y_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row-1,Y_CHAR);
- X PUTCH(Column-1,Row,Y_CHAR);
- X PUTCH(Column,Row+1,Y_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* GREEN PIECES */
- X case G_TYPE :
- X case G_TYPE-2 : /* checked */
- X if (IS_FREE(Column-2,Row) && IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-2,Row,G_CHAR);
- X PUTCH(Column-1,Row+1,G_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case G_TYPE-1 :
- X case G_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-2,Row) &&
- X IS_FREE(Column-2,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row-1,G_CHAR);
- X PUTCH(Column-2,Row,G_CHAR);
- X PUTCH(Column-2,Row+1,G_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* BLUE PIECES */
- X case B_TYPE : /* checked */
- X if (IS_FREE(Column-2,Row) && IS_FREE(Column,Row+1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-2,Row,B_CHAR);
- X PUTCH(Column,Row+1,B_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column-1,Row+1)) {
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row-1,B_CHAR);
- X PUTCH(Column-1,Row,B_CHAR);
- X PUTCH(Column-1,Row+1,B_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-2 : /* checked */
- X if (IS_FREE(Column-2,Row-1) && IS_FREE(Column-2,Row)) {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-2,Row-1,B_CHAR);
- X PUTCH(Column-2,Row,B_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column-2,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row-1,B_CHAR);
- X PUTCH(Column-1,Row,B_CHAR);
- X PUTCH(Column-2,Row+1,B_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* VIOLET PIECES */
- X case V_TYPE :
- X case V_TYPE-2 : /* checked */
- X if (IS_FREE(Column-2,Row)) {
- X PUTCH(Column+2,Row,NO_CHAR);
- X PUTCH(Column-2,Row,V_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X case V_TYPE-1 :
- X case V_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column-1,Row+1) && IS_FREE(Column-1,Row+2)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column,Row+2,NO_CHAR);
- X PUTCH(Column-1,Row-1,V_CHAR);
- X PUTCH(Column-1,Row,V_CHAR);
- X PUTCH(Column-1,Row+1,V_CHAR);
- X PUTCH(Column-1,Row+2,V_CHAR);
- X Column -=1;
- X }
- X else goto beepout;
- X goto out;
- X default :
- X printf("illegal piece Type=%d!!\n",Type);
- X exit();
- X }
- Xbeepout:
- X if (Beep) beep();
- Xout:
- X refresh();
- X}
- X
- END_OF_FILE
- if test 6741 -ne `wc -c <'MoveL.c'`; then
- echo shar: \"'MoveL.c'\" unpacked with wrong size!
- fi
- # end of 'MoveL.c'
- fi
- if test -f 'MoveR.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MoveR.c'\"
- else
- echo shar: Extracting \"'MoveR.c'\" \(6659 characters\)
- sed "s/^X//" >'MoveR.c' <<'END_OF_FILE'
- X
- X#include <curses.h>
- X#include "tet.h"
- X/*********************************************************************/
- X/* Switch on type of piece, find out if I can move right */
- X/* If so, then do it */
- X/*********************************************************************/
- XMoveRight()
- X{
- Xswitch (Type) {
- X
- X /* WHITE PIECES */
- X case W_TYPE : /* */
- X if (IS_FREE(Column+2,Row) && IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+2,Row,W_CHAR);
- X PUTCH(Column+1,Row+1,W_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-1 : /* */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+2,Row) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,W_CHAR);
- X PUTCH(Column+2,Row,W_CHAR);
- X PUTCH(Column+1,Row+1,W_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-2 : /* */
- X if (IS_FREE(Column+2,Row) && IS_FREE(Column+1,Row-1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+2,Row,W_CHAR);
- X PUTCH(Column+1,Row-1,W_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-3 : /* */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,W_CHAR);
- X PUTCH(Column+1,Row,W_CHAR);
- X PUTCH(Column+1,Row+1,W_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* RED PIECES */
- X case R_TYPE : /* */
- X if (IS_FREE(Column,Row+1) && IS_FREE(Column+2,Row)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column+2,Row,R_CHAR);
- X PUTCH(Column,Row+1,R_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-1 : /* */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+2,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,R_CHAR);
- X PUTCH(Column+1,Row,R_CHAR);
- X PUTCH(Column+2,Row+1,R_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-2 : /* */
- X if (IS_FREE(Column+2,Row-1) && IS_FREE(Column+2,Row)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column+2,Row,R_CHAR);
- X PUTCH(Column+2,Row-1,R_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-3 : /* */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,R_CHAR);
- X PUTCH(Column+1,Row,R_CHAR);
- X PUTCH(Column+1,Row+1,R_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* TAN PIECES */
- X case T_TYPE :
- X case T_TYPE-1 :
- X case T_TYPE-2 :
- X case T_TYPE-3 : /* */
- X if (IS_FREE(Column+2,Row) && IS_FREE(Column+2,Row+1)) {
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+2,Row,T_CHAR);
- X PUTCH(Column+2,Row+1,T_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* YELLOW PIECES */
- X case Y_TYPE :
- X case Y_TYPE-2 : /* checked */
- X if (IS_FREE(Column+2,Row) && IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column+2,Row,Y_CHAR);
- X PUTCH(Column+1,Row+1,Y_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case Y_TYPE-1 :
- X case Y_TYPE-3 : /* */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+2,Row) &&
- X IS_FREE(Column+2,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,Y_CHAR);
- X PUTCH(Column+2,Row,Y_CHAR);
- X PUTCH(Column+2,Row+1,Y_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* GREEN PIECES */
- X case G_TYPE :
- X case G_TYPE-2 : /* checked */
- X if (IS_FREE(Column+1,Row) && IS_FREE(Column+2,Row+1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row,G_CHAR);
- X PUTCH(Column+2,Row+1,G_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case G_TYPE-1 :
- X case G_TYPE-3 : /* */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,G_CHAR);
- X PUTCH(Column+1,Row,G_CHAR);
- X PUTCH(Column,Row+1,G_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* BLUE PIECES */
- X case B_TYPE : /* checked */
- X if (IS_FREE(Column+2,Row) && IS_FREE(Column+2,Row+1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column+2,Row,B_CHAR);
- X PUTCH(Column+2,Row+1,B_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-1 : /* checked */
- X if (IS_FREE(Column+2,Row-1) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+2,Row-1,B_CHAR);
- X PUTCH(Column+1,Row,B_CHAR);
- X PUTCH(Column+1,Row+1,B_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-2 : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column+2,Row)) {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,B_CHAR);
- X PUTCH(Column+2,Row,B_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-3 : /* checked */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,B_CHAR);
- X PUTCH(Column+1,Row,B_CHAR);
- X PUTCH(Column+1,Row+1,B_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* VIOLET PIECES */
- X case V_TYPE :
- X case V_TYPE-2 : /* checked */
- X if (IS_FREE(Column+3,Row)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+3,Row,V_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X case V_TYPE-1 :
- X case V_TYPE-3 : /* checked */
- X if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+1,Row+1) && IS_FREE(Column+1,Row+2)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column,Row+2,NO_CHAR);
- X PUTCH(Column+1,Row-1,V_CHAR);
- X PUTCH(Column+1,Row,V_CHAR);
- X PUTCH(Column+1,Row+1,V_CHAR);
- X PUTCH(Column+1,Row+2,V_CHAR);
- X Column +=1;
- X }
- X else goto beepout;
- X goto out;
- X default :
- X printf("illegal piece Type=%d!!\n",Type);
- X exit();
- X }
- Xbeepout:
- X if (Beep) beep();
- Xout:
- X refresh();
- X}
- X
- END_OF_FILE
- if test 6659 -ne `wc -c <'MoveR.c'`; then
- echo shar: \"'MoveR.c'\" unpacked with wrong size!
- fi
- # end of 'MoveR.c'
- fi
- if test -f 'NewP.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'NewP.c'\"
- else
- echo shar: Extracting \"'NewP.c'\" \(3103 characters\)
- sed "s/^X//" >'NewP.c' <<'END_OF_FILE'
- X
- X#include <curses.h>
- X#include "tet.h"
- X/*********************************************************************/
- X/* A new piece is created on the game board if possible */
- X/* returns 0 if unable to do it */
- X/*********************************************************************/
- XNewPiece()
- X{
- XFallingDown = 0; /* true when fall key is pressed */
- XType = ((int)(mrand48() % 4) + 4) * 4; /* random number 4 8 16 20 24 or 28 */
- X/* printf("DEBUG:NewPiece Type = %d\n",Type); */
- X
- Xswitch (Type) {
- X case W_TYPE : /* checked */
- X if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
- X IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL,STARTROW+1)) {
- X PUTCH(STARTCOL-1,STARTROW,W_CHAR);
- X PUTCH(STARTCOL,STARTROW,W_CHAR);
- X PUTCH(STARTCOL+1,STARTROW,W_CHAR);
- X PUTCH(STARTCOL,STARTROW+1,W_CHAR);
- X }
- X else {
- X return(0);
- X }
- X break;
- X case R_TYPE : /* checked */
- X if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
- X IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL-1,STARTROW+1)) {
- X PUTCH(STARTCOL-1,STARTROW,R_CHAR);
- X PUTCH(STARTCOL,STARTROW,R_CHAR);
- X PUTCH(STARTCOL+1,STARTROW,R_CHAR);
- X PUTCH(STARTCOL-1,STARTROW+1,R_CHAR);
- X }
- X else return(0);
- X break;
- X case T_TYPE : /* checked */
- X if (IS_FREE(STARTCOL,STARTROW) && IS_FREE(STARTCOL,STARTROW+1) &&
- X IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL+1,STARTROW+1)) {
- X PUTCH(STARTCOL,STARTROW,T_CHAR);
- X PUTCH(STARTCOL,STARTROW+1,T_CHAR);
- X PUTCH(STARTCOL+1,STARTROW,T_CHAR);
- X PUTCH(STARTCOL+1,STARTROW+1,T_CHAR);
- X }
- X else return(0);
- X break;
- X case Y_TYPE : /* checked */
- X if (IS_FREE(STARTCOL-1,STARTROW+1) && IS_FREE(STARTCOL,STARTROW+1) &&
- X IS_FREE(STARTCOL,STARTROW) && IS_FREE(STARTCOL+1,STARTROW)) {
- X PUTCH(STARTCOL-1,STARTROW+1,Y_CHAR);
- X PUTCH(STARTCOL,STARTROW+1,Y_CHAR);
- X PUTCH(STARTCOL,STARTROW,Y_CHAR);
- X PUTCH(STARTCOL+1,STARTROW,Y_CHAR);
- X }
- X else return(0);
- X break;
- X case G_TYPE : { /* checked */
- X if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
- X IS_FREE(STARTCOL,STARTROW+1) && IS_FREE(STARTCOL+1,STARTROW+1)) {
- X PUTCH(STARTCOL-1,STARTROW,G_CHAR);
- X PUTCH(STARTCOL,STARTROW,G_CHAR);
- X PUTCH(STARTCOL,STARTROW+1,G_CHAR);
- X PUTCH(STARTCOL+1,STARTROW+1,G_CHAR);
- X }
- X else return(0);
- X break; }
- X case B_TYPE : /* checked */
- X if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
- X IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL+1,STARTROW+1)) {
- X PUTCH(STARTCOL-1,STARTROW,B_CHAR);
- X PUTCH(STARTCOL,STARTROW,B_CHAR);
- X PUTCH(STARTCOL+1,STARTROW,B_CHAR);
- X PUTCH(STARTCOL+1,STARTROW+1,B_CHAR);
- X }
- X else return(0);
- X break;
- X case V_TYPE : /* checked */
- X if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
- X IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL+2,STARTROW)) {
- X PUTCH(STARTCOL-1,STARTROW,V_CHAR);
- X PUTCH(STARTCOL,STARTROW,V_CHAR);
- X PUTCH(STARTCOL+1,STARTROW,V_CHAR);
- X PUTCH(STARTCOL+2,STARTROW,V_CHAR);
- X }
- X else return(0);
- X break;
- X default : printf("illegal piece Type=%d!!\n",Type); exit();
- X }
- Xrefresh();
- XRow=STARTROW; Column=STARTCOL; /* all pieces start at same point */
- X}
- END_OF_FILE
- if test 3103 -ne `wc -c <'NewP.c'`; then
- echo shar: \"'NewP.c'\" unpacked with wrong size!
- fi
- # end of 'NewP.c'
- fi
- if test -f 'Rotate.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Rotate.c'\"
- else
- echo shar: Extracting \"'Rotate.c'\" \(6209 characters\)
- sed "s/^X//" >'Rotate.c' <<'END_OF_FILE'
- X
- X#include <curses.h>
- X#include "tet.h"
- X/*********************************************************************/
- X/* Switch on type of piece, find out if I can rotate */
- X/* If so, then do it */
- X/*********************************************************************/
- XRotate()
- X{
- Xswitch (Type) {
- X /* WHITE PIECES */
- X case W_TYPE : /* checked */
- X if (IS_FREE(Column,Row-1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,W_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row)) {
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,W_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-2 : /* checked */
- X if (IS_FREE(Column,Row+1)) {
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row+1,W_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case W_TYPE-3 : /* checked */
- X if (IS_FREE(Column+1,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,W_CHAR);
- X Type = W_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* RED PIECES */
- X case R_TYPE : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column,Row-1,R_CHAR);
- X PUTCH(Column,Row+1,R_CHAR);
- X PUTCH(Column+1,Row+1,R_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row-1) &&
- X IS_FREE(Column+1,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,R_CHAR);
- X PUTCH(Column+1,Row-1,R_CHAR);
- X PUTCH(Column+1,Row,R_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-2 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column,Row-1) &&
- X IS_FREE(Column,Row+1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row-1,R_CHAR);
- X PUTCH(Column,Row-1,R_CHAR);
- X PUTCH(Column,Row+1,R_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case R_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column-1,Row+1) &&
- X IS_FREE(Column+1,Row)) {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,R_CHAR);
- X PUTCH(Column-1,Row+1,R_CHAR);
- X PUTCH(Column+1,Row,R_CHAR);
- X Type = R_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* TAN PIECES */
- X case T_TYPE :
- X case T_TYPE-1 :
- X case T_TYPE-2 :
- X case T_TYPE-3 : goto out;
- X
- X /* YELLOW PIECES */
- X case Y_TYPE :
- X case Y_TYPE-2 : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,Y_CHAR);
- X PUTCH(Column+1,Row+1,Y_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case Y_TYPE-1 :
- X case Y_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row+1)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row+1,Y_CHAR);
- X PUTCH(Column,Row+1,Y_CHAR);
- X Type = Y_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* GREEN PIECES */
- X case G_TYPE :
- X case G_TYPE-2 : /* checked */
- X if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1)) {
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row+1,G_CHAR);
- X PUTCH(Column,Row-1,G_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case G_TYPE-1 :
- X case G_TYPE-3 : /* checked */
- X if (IS_FREE(Column,Row+1) && IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,G_CHAR);
- X PUTCH(Column+1,Row+1,G_CHAR);
- X Type = G_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X
- X /* BLUE PIECES */
- X case B_TYPE : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) &&
- X IS_FREE(Column+1,Row-1)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+1,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,B_CHAR);
- X PUTCH(Column,Row+1,B_CHAR);
- X PUTCH(Column+1,Row-1,B_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-1 : /* checked */
- X if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) &&
- X IS_FREE(Column+1,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column+1,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row-1,B_CHAR);
- X PUTCH(Column-1,Row,B_CHAR);
- X PUTCH(Column+1,Row,B_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-2 : /* checked */
- X if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1) &&
- X IS_FREE(Column,Row+1)) {
- X PUTCH(Column-1,Row-1,NO_CHAR);
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column-1,Row+1,B_CHAR);
- X PUTCH(Column,Row-1,B_CHAR);
- X PUTCH(Column,Row+1,B_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case B_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+1,Row+1)) {
- X PUTCH(Column-1,Row+1,NO_CHAR);
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column-1,Row,B_CHAR);
- X PUTCH(Column+1,Row,B_CHAR);
- X PUTCH(Column+1,Row+1,B_CHAR);
- X Type = B_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X
- X /* VIOLET PIECES */
- X case V_TYPE :
- X case V_TYPE-2 : /* checked */
- X if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) &&
- X IS_FREE(Column,Row+2)) {
- X PUTCH(Column-1,Row,NO_CHAR);
- X PUTCH(Column+1,Row,NO_CHAR);
- X PUTCH(Column+2,Row,NO_CHAR);
- X PUTCH(Column,Row-1,V_CHAR);
- X PUTCH(Column,Row+1,V_CHAR);
- X PUTCH(Column,Row+2,V_CHAR);
- X Type--;
- X }
- X else goto beepout;
- X goto out;
- X case V_TYPE-1 :
- X case V_TYPE-3 : /* checked */
- X if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) &&
- X IS_FREE(Column+2,Row)) {
- X PUTCH(Column,Row-1,NO_CHAR);
- X PUTCH(Column,Row+1,NO_CHAR);
- X PUTCH(Column,Row+2,NO_CHAR);
- X PUTCH(Column-1,Row,V_CHAR);
- X PUTCH(Column,Row,V_CHAR);
- X PUTCH(Column+1,Row,V_CHAR);
- X PUTCH(Column+2,Row,V_CHAR);
- X Type = V_TYPE;
- X }
- X else goto beepout;
- X goto out;
- X default :
- X printf("illegal piece Type=%d!!\n",Type);
- X exit();
- X }
- Xbeepout:
- X if (Beep) beep();
- Xout:
- X refresh();
- X}
- X
- END_OF_FILE
- if test 6209 -ne `wc -c <'Rotate.c'`; then
- echo shar: \"'Rotate.c'\" unpacked with wrong size!
- fi
- # end of 'Rotate.c'
- fi
- if test -f 'tet.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tet.c'\"
- else
- echo shar: Extracting \"'tet.c'\" \(9501 characters\)
- sed "s/^X//" >'tet.c' <<'END_OF_FILE'
- X/* Tetrix by quentin */
- X
- X#include <signal.h>
- X#include <sys/ioctl.h>
- X#include <fcntl.h>
- X#include <stdio.h>
- X#include <curses.h>
- X#include "tet.h"
- X
- X/********** Some global variable declarations ************/
- Xint Type; /* type specifies rotation, shape and color of blocks */
- Xint Row; /* Row of pivot point of block */
- Xint Column; /* Column of pivot point of block */
- Xint Pause; /* Time between movements this block */
- Xint CurrentPause; /* Time between movements per level */
- Xint FallingDown; /* True when space bar is pressed */
- Xint Beep;
- Xchar Key; /* holds last key polled */
- X
- X#define SCORE_FILE "/usr/tmp/.TetScores"
- Xchar ScoreString[10];
- Xstruct ScoreStruct {
- X char Name[10];
- X int Score;
- X} High[10];
- Xint ThisScore,HighsChanged;
- X
- Xchar *ttyname();
- Xchar combuf[2];
- Xstruct termio origtty, tty;
- Xchar Board[BOARD_WIDE][BOARD_HIGH];
- Xchar Temp[BOARD_WIDE][BOARD_HIGH]; /* temp storage for TestRows */
- X
- X/* debug flash to screen */
- X#define FLASHMSG(x)
- X/*
- X#define FLASHMSG(x) { mvaddstr(23,0," "); \
- X mvaddstr(23,0,x); \
- X refresh(); }
- X*/
- X#define UPSCORE(x) { ThisScore += x; \
- X sprintf((char *)ScoreString,"%-d",ThisScore); \
- X mvaddstr(1,46,ScoreString); }
- X
- X#define NULL_KEY '\0'
- X#define FALL_KEY ' '
- X#define RIGHT_KEY 'l'
- X#define LEFT_KEY 'j'
- X#define ROTATE_KEY 'k'
- X#define L_RIGHT_KEY 'f' /* for south paws */
- X#define L_LEFT_KEY 's'
- X#define L_ROTATE_KEY 'd'
- X#define QUIT_KEY 'q'
- X#define BEEP_KEY 'b'
- X#define BOSS_KEY '\033'
- X#define PLAY_KEY 'p'
- X#define SCORE_KEY 'h'
- X#define MENU_KEY 'm'
- X
- X/**************************************************MAIN*****/
- Xmain()
- X{
- X Init();
- X for ( ; ; ) {
- X NewGame();
- X Play();
- X ScoreIt();
- X DrawScore();
- X }
- X}
- X
- X/*************************************************************/
- XInit()
- X{
- X register char *ttnam, *p;
- X register int x,y,i,fd;
- X int timein;
- X
- X time(&timein); /* get start time */
- X srand48(timein); /* start rand randomly */
- X
- X ttnam = ttyname (0);
- X close (0);
- X open (ttnam, O_NDELAY);
- X /*
- X * setup raw mode, no echo
- X */
- X ioctl (0, TCGETA, &origtty);
- X ioctl (0, TCGETA, &tty);
- X tty.c_iflag &= 077;
- X tty.c_oflag &= 077700;
- X tty.c_lflag = 0201;
- X tty.c_cc[4] = 1;
- X ioctl (1, TCSETAW, &tty);
- X signal(SIGINT, SIG_IGN);
- X
- X Beep=0;
- X HighsChanged = 0;
- X ScoreIt();
- X initscr();
- X /* initilialize board to spaces */
- X for (x=0; x<BOARD_WIDE; x++)
- X for (y=0; y<BOARD_HIGH; y++)
- X PUTCH(x,y,NO_CHAR);
- X erase();
- X DrawMenu();
- X refresh();
- X}
- X
- X/**************************************************************/
- XNewGame()
- X{
- X register int x,y;
- X
- X CurrentPause=0;
- X
- X while (!CurrentPause) {
- X GetKey();
- X switch (Key) {
- X case BEEP_KEY : Beep = !Beep ;
- X if (Beep) beep();
- X break;
- X case SCORE_KEY : DrawScore(); break;
- X case MENU_KEY : DrawMenu(); break;
- X case BOSS_KEY : Boss(); break;
- X case PLAY_KEY : CurrentPause=150; break;
- X case QUIT_KEY : Leave();
- X }
- X }
- X /* initilialize board to spaces */
- X for (x=0; x<BOARD_WIDE; x++)
- X for (y=0; y<BOARD_HIGH; y++)
- X PUTCH(x,y,NO_CHAR);
- X ThisScore=0;
- X mvaddstr(1,42,"| ...... |");
- X UPSCORE(0);
- X
- X}
- X
- X/******************************************************************/
- XDrawMenu()
- X{
- X register int y;
- X erase();
- X
- X /* draw score border */
- X mvaddstr(0,42,".----------.");
- X mvaddstr(1,42,"| ...... |");
- X mvaddstr(2,42,"`----------'");
- X UPSCORE(0);
- X
- X /* draw menu */
- X mvaddstr( 4,35,".---------------------------.");
- X mvaddstr( 5,35,"| |");
- X mvaddstr( 6,35,"| .. Menu .. |");
- X mvaddstr( 7,35,"| |");
- X mvaddstr( 8,35,"| h .... high scores |");
- X mvaddstr( 9,35,"| b .... toggle beep |");
- X mvaddstr(10,35,"| p .... play |");
- X mvaddstr(11,35,"| q .... quit |");
- X mvaddstr(12,35,"| |");
- X mvaddstr(13,35,"| s or j .... move left |");
- X mvaddstr(14,35,"| d or k .... rotate piece |");
- X mvaddstr(15,35,"| f or l .... move right |");
- X mvaddstr(16,35,"| spc .... fall piece |");
- X mvaddstr(17,35,"| esc .... pause |");
- X mvaddstr(18,35,"| |");
- X mvaddstr(19,35,"| LATEST: allow concurrent |");
- X mvaddstr(20,35,"| high score setting |");
- X mvaddstr(21,35,"`---------------------------'");
- X
- X /* draw game border */
- X mvaddstr(0,14, ".----------.");
- X mvaddstr(21,14,"`----------'");
- X for (y=1; y<21; y++)
- X mvaddstr(y,14,"| |");
- X
- X /* display the title */
- X mvaddstr(3,17,"TETRIX");
- X refresh();
- X}
- X
- X/**************************************************************/
- XPlay()
- X{
- Xwhile ((Key != QUIT_KEY) && NewPiece()) {
- X FallingDown = 0;
- X do { /* do until we can't Advance the piece */
- X if (FallingDown) Pause = 0;
- X else Pause = CurrentPause;
- X while (Pause) { /* do this until pause runs out */
- X Pause--;
- X switch (Key) {
- X case BOSS_KEY : Boss(); break;
- X case QUIT_KEY : CurrentPause = 0;
- X case FALL_KEY : FallingDown = 1;
- X UPSCORE(20-Row);
- X Pause = 0; break;
- X case RIGHT_KEY :
- X case L_RIGHT_KEY : MoveRight(); break;
- X case LEFT_KEY :
- X case L_LEFT_KEY : MoveLeft(); break;
- X case ROTATE_KEY :
- X case L_ROTATE_KEY : Rotate(); break;
- X case NULL_KEY : break;
- X default : if (Beep) beep();
- X }
- X GetKey();
- X }
- X } while (AdvancePiece());
- X UPSCORE(5);
- X TestRows();
- X }
- X}
- X
- X/*********************************************************************/
- XScoreIt()
- X{
- X register int oldmask,fd,i,j;
- X
- X oldmask = umask(0);
- X if ((fd=open(SCORE_FILE,O_CREAT|O_RDONLY,0666)) != -1) {
- X read(fd,High,sizeof(High));
- X close(fd);
- X }
- X else {
- X for(i=0; i<10; i++)
- X High[i].Score = 0;
- X for(i=0; i<10; i++)
- X strncpy(" ",High[i].Name,10);
- X }
- X umask(oldmask);
- X
- X for (i=0; i<10; i++) /* place this guy */
- X if (High[i].Score <= ThisScore) break;
- X
- X if (i < 10 ) /* insert this score */
- X {
- X HighsChanged = 1;
- X for (j=9; j>i; j--) /* move down others */
- X if (High[j-1].Score)
- X {
- X High[j].Score = High[j-1].Score;
- X strncpy(High[j].Name,High[j-1].Name,10);
- X }
- X cuserid((char *) High[i].Name);
- X High[i].Score = ThisScore;
- X }
- X
- X if (HighsChanged)
- X {
- X if ((fd=open(SCORE_FILE,O_RDWR)) != -1) {
- X write(fd,High,sizeof(High));
- X close(fd);
- X }
- X else mvaddstr(22,0,"Couldn't open high score file.");
- X }
- X
- X}
- X
- X/***********************************************************************/
- XDrawScore()
- X{
- X register int j;
- X
- X mvaddstr( 5,35,"| Hit 'm' for menu |");
- X mvaddstr( 6,35,"| |");
- X mvaddstr( 7,35,"| HIGH SCORES |");
- X mvaddstr( 8,35,"| 1. |");
- X mvaddstr( 9,35,"| 2. |");
- X mvaddstr(10,35,"| 3. |");
- X mvaddstr(11,35,"| 4. |");
- X mvaddstr(12,35,"| 5. |");
- X mvaddstr(13,35,"| 6. |");
- X mvaddstr(14,35,"| 7. |");
- X mvaddstr(15,35,"| 8. |");
- X mvaddstr(16,35,"| 9. |");
- X mvaddstr(17,35,"|10. |");
- X mvaddstr(18,35,"| |");
- X mvaddstr(19,35,"| |");
- X mvaddstr(20,35,"| |");
- X
- X for (j=0; j<10; j++)
- X if (High[j].Score)
- X {
- X mvprintw(j+8,41,"%-s",(char *)High[j].Name);
- X mvprintw(j+8,54,"%d",High[j].Score);
- X }
- X refresh();
- X
- X}
- X
- X/*********************************************************************/
- XBoss()
- X{ register int x,y;
- X
- X clear();
- X refresh();
- X ioctl (0, TCSETA, &origtty);
- X system("sh </dev/tty >/dev/tty");
- X ioctl (1, TCSETAW, &tty);
- X clear();
- X DrawMenu();
- X /* restore board */
- X for (x=0; x<BOARD_WIDE; x++)
- X for (y=0; y<BOARD_HIGH; y++)
- X PUTCH(x,y,Board[x][y]);
- X refresh();
- X
- X}
- X
- X/*********************************************************************/
- XGetKey()
- X{
- X/* fflush(stdout); */
- X Key = NULL_KEY;
- X top:
- X if (read (0, combuf, 1) == 0)
- X return;
- X else Key = (*combuf&0177);
- X goto top;
- X}
- X
- X/************************************************************************/
- X/* Could be a macro for speed but cpp runs out of tree space in CanMove */
- XIS_FREE(x,y)
- Xint x,y;
- X{
- X if ((y < 0) || (y >= BOARD_HIGH) || (x < 0) || (x >= BOARD_WIDE))
- X return(0);
- X if (Board[x][y] != NO_CHAR)
- X return(0);
- X else return(1);
- X}
- X
- X/*********************************************************************/
- XTestRows()
- X{ register int x,y,tempy,fullrow;
- X int marked[BOARD_HIGH];
- X
- Xfor (y=0; y<BOARD_HIGH; y++) {
- X marked[y] = 0;
- X for (x=0; x<BOARD_WIDE; x++)
- X Temp[x][y] = NO_CHAR;
- X }
- X
- X/* main loop to traverse Board, looking for fullrows */
- X/* as it looks, it copies non full ones over to Temp */
- Xtempy=BOARD_HIGH-1;
- Xfor (y=BOARD_HIGH-1; y>=0; y--) {
- X fullrow = 1;
- X for (x=0; x<BOARD_WIDE; x++) /* check for any holes at all */
- X if (IS_FREE(x,y)) { fullrow = 0; break; }
- X if (fullrow) {
- X marked[y]++;
- X CurrentPause--; /* speed up the game */
- X }
- X else {
- X for (x=0; x<BOARD_WIDE; x++)
- X Temp[x][tempy] = Board[x][y];
- X tempy--;
- X }
- X }
- X
- X/* flash the rows that will die */
- Xfor (tempy=1; tempy<5; tempy++)
- X for (y=BOARD_HIGH-1; y>=0; y--)
- X if (marked[y]) {
- X UPSCORE(30-y);
- X for (x=0; x<BOARD_WIDE; x++)
- X PUTCH(x,y,BRITE_CHAR);
- X refresh();
- X for (x=0; x<BOARD_WIDE; x++)
- X PUTCH(x,y,NO_CHAR);
- X refresh();
- X }
- X
- X/* Move temp back to Board */
- Xfor (y=BOARD_HIGH-1; y>=0; y--) {
- X for (x=0; x<BOARD_WIDE; x++)
- X PUTCH(x,y,Temp[x][y]);
- X refresh();
- X }
- X}
- X
- X/***********************************************************/
- XLeave()
- X{
- X erase();
- X mvaddstr(22,48,"Tetrix says Bye\n");
- X mvaddstr(23,0,"");
- X refresh();
- X sleep(1);
- X ioctl (0, TCSETA, &origtty);
- X exit(0);
- X}
- END_OF_FILE
- if test 9501 -ne `wc -c <'tet.c'`; then
- echo shar: \"'tet.c'\" unpacked with wrong size!
- fi
- # end of 'tet.c'
- fi
- echo shar: End of shell archive.
- exit 0
-